package com.fimmlps.reronge.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fimmlps.reronge.entity.EntryUser;
import com.fimmlps.reronge.mapper.EntryUserMapper;
import jakarta.annotation.Resource;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

import java.util.logging.Logger;

@Service
public class CustomUserServiceImpl implements UserDetailsService {
    @Resource
    EntryUserMapper entryUserMapper;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        Logger.getGlobal().info("==="+username);
        EntryUser entryUser = entryUserMapper.selectOne(new QueryWrapper<EntryUser>().eq("user_name",username));
        return User.withUsername(entryUser!=null?entryUser.getUserName():"testName")
                .password((entryUser!=null?entryUser.getUserPassword():""))
                .build();
    }
}
